package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import util.DBUtil;

import model.Duty;
import model.SkillGrade;
import dao.SkillGradeDAO;

public class SkillGradeDAOImpl implements SkillGradeDAO {
	private DBUtil dbu = new DBUtil();
	private Connection conn = null;
	private PreparedStatement pstat = null;
	private ResultSet rs = null;
	public List<SkillGrade> getAll() {

		List <SkillGrade> list=new ArrayList<SkillGrade>();
		try {
			conn = dbu.getConnection();
			String sql="select * from skillgrade";
			pstat=conn.prepareStatement(sql);
			rs = pstat.executeQuery();
			while (rs.next()) {
				SkillGrade skillGrade  = new SkillGrade();
				skillGrade.setId(rs.getInt(1));
				skillGrade.setName(rs.getString(2));
				list.add(skillGrade);
			}
		}catch (Exception e) {
			e.printStackTrace();
		} finally {
			dbu.closeConnection(conn, pstat, rs);
		}
		return list;

	}

	public SkillGrade getById(int id) {
		conn= dbu.getConnection();
		SkillGrade sk=new SkillGrade();
		try {
			pstat=conn.prepareStatement("select * from skillgrade where id="+id);
			rs=	pstat.executeQuery();
			while(rs.next()){
			sk.setId(rs.getInt("ID"));
			sk.setName(rs.getString("NAME"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			dbu.closeConnection(conn, pstat, rs);
		}
		return sk;
	}

	public SkillGrade geyByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

}
